//
//  OrderListCell.m
//  student
//
//  Created by JCai on 2018/10/22.
//  Copyright © 2018年 higer. All rights reserved.
//

#define kLineColor [UIColor colorWithRed:238/255.0f green:238/255.0f blue:238/255.0f alpha:1.0f]

#import "OrderListCell.h"
#import "UITitleInfo.h"
#import "OrderListModel.h"


@interface OrderListCell ()

@property (nonatomic, strong) UITitleInfo *orderNumberLabel;
@property (nonatomic, strong) UITitleInfo *orderTimeLabel;
@property (nonatomic, strong) UITitleInfo *subjectLabel;
@property (nonatomic, strong) UITitleInfo *serviceLabel;
@property (nonatomic, strong) UITitleInfo *fieldLabel;
@property (nonatomic, strong) UITitleInfo *carLabel;
@property (nonatomic, strong) UITitleInfo *moneyTypeLabel;
@property (nonatomic, strong) UITitleInfo *buyTimeLabel;
@property (nonatomic, strong) UITitleInfo *buyNumberLabel;
@property (nonatomic, strong) UITitleInfo *moneyLabel;
@property (nonatomic, strong) UITitleInfo *discountLabel;
@property (nonatomic, strong) UITitleInfo *discountReasonLabel;
@property (nonatomic, strong) UITitleInfo *payLabel;

@property (nonatomic, strong) UILabel *stateLabel;

@end


@implementation OrderListCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier];
    if (self) {
        [self setBackgroundColor:[UIColor whiteColor]];
        
        CGRect otherFrame = CGRectMake(0,
                                       10*SCALING,
                                       SCREEN_WIDTH - 80 * SCALING,
                                       26 * SCALING);
        [self otherFrame:otherFrame];
        
        CGRect stateFrame = CGRectMake(SCREEN_WIDTH-80*SCALING,
                                       (OrderListCellHeight - 30*SCALING)/2.0f,
                                       70*SCALING,
                                       30*SCALING);
        UILabel *stateLabel = [[UILabel alloc] initWithFrame:stateFrame];
        [stateLabel setTextColor:[UIColor blackColor]];
        [stateLabel setBackgroundColor:[UIColor clearColor]];
        [stateLabel setTextAlignment:NSTextAlignmentLeft];
        [stateLabel setFont:[UIFont systemFontOfSize:14.0f* SCALING]];
        [self addSubview:stateLabel];
        self.stateLabel = stateLabel;
        
        CGRect lineFrame = CGRectMake(10*SCALING, OrderListCellHeight - 0.5, SCREEN_WIDTH-20*SCALING, 0.5);
        UIImageView *lineImageView = [[UIImageView alloc] initWithFrame:lineFrame];
        [lineImageView setBackgroundColor:kLineColor];
        [self addSubview:lineImageView];
    }
    return self;
}

#pragma mark -
- (void)otherFrame:(CGRect)frame
{
    CGRect tempFrame = CGRectMake(CGRectGetMinX(frame),
                                  CGRectGetMinY(frame),
                                  CGRectGetWidth(frame),
                                  CGRectGetHeight(frame));
    _orderNumberLabel = [UITitleInfo initTitleInfo:self frame:tempFrame title:@"订单编号:"];
    [_orderNumberLabel setTitle:[UIFont systemFontOfSize:14.0f*SCALING]
                         :[UIColor grayColor]
                         :NSTextAlignmentCenter];
    [_orderNumberLabel setInfo:[UIFont systemFontOfSize:14.0f*SCALING]
                        :[UIColor blackColor]
                        :NSTextAlignmentLeft];
    [self addSubview:_orderNumberLabel];
    
    tempFrame.origin.y += CGRectGetHeight(tempFrame);
    _orderTimeLabel = [UITitleInfo initTitleInfo:self frame:tempFrame title:@"交易日期:"];
    [_orderTimeLabel setTitle:[UIFont systemFontOfSize:14.0f*SCALING]
                          :[UIColor grayColor]
                          :NSTextAlignmentCenter];
    [_orderTimeLabel setInfo:[UIFont systemFontOfSize:14.0f*SCALING]
                         :[UIColor blackColor]
                         :NSTextAlignmentLeft];
    [self addSubview:_orderTimeLabel];
    
    tempFrame.origin.y += CGRectGetHeight(tempFrame);
    _subjectLabel = [UITitleInfo initTitleInfo:self frame:tempFrame title:@"科目类型:"];
    [_subjectLabel setTitle:[UIFont systemFontOfSize:14.0f*SCALING]
                        :[UIColor grayColor]
                        :NSTextAlignmentCenter];
    [_subjectLabel setInfo:[UIFont systemFontOfSize:14.0f*SCALING]
                       :[UIColor blackColor]
                       :NSTextAlignmentLeft];
    [self addSubview:_subjectLabel];
    
    tempFrame.origin.y += CGRectGetHeight(tempFrame);
    _serviceLabel = [UITitleInfo initTitleInfo:self frame:tempFrame title:@"服务机构:"];
    [_serviceLabel setTitle:[UIFont systemFontOfSize:14.0f*SCALING]
                        :[UIColor grayColor]
                        :NSTextAlignmentCenter];
    [_serviceLabel setInfo:[UIFont systemFontOfSize:14.0f*SCALING]
                       :[UIColor blackColor]
                       :NSTextAlignmentLeft];
    [self addSubview:_serviceLabel];
    
    tempFrame.origin.y += CGRectGetHeight(tempFrame);
    _fieldLabel = [UITitleInfo initTitleInfo:self frame:tempFrame title:@"训练场地:"];
    [_fieldLabel setTitle:[UIFont systemFontOfSize:14.0f*SCALING]
                          :[UIColor grayColor]
                          :NSTextAlignmentCenter];
    [_fieldLabel setInfo:[UIFont systemFontOfSize:14.0f*SCALING]
                         :[UIColor blackColor]
                         :NSTextAlignmentLeft];
    [self addSubview:_fieldLabel];
    
    tempFrame.origin.y += CGRectGetHeight(tempFrame);
    _carLabel = [UITitleInfo initTitleInfo:self frame:tempFrame title:@"模拟车型:"];
    [_carLabel setTitle:[UIFont systemFontOfSize:14.0f*SCALING]
                          :[UIColor grayColor]
                          :NSTextAlignmentCenter];
    [_carLabel setInfo:[UIFont systemFontOfSize:14.0f*SCALING]
                         :[UIColor blackColor]
                         :NSTextAlignmentLeft];
    [self addSubview:_carLabel];
    
    tempFrame.origin.y += CGRectGetHeight(tempFrame);
    _moneyTypeLabel = [UITitleInfo initTitleInfo:self frame:tempFrame title:@"收费类型:"];
    [_moneyTypeLabel setTitle:[UIFont systemFontOfSize:14.0f*SCALING]
                          :[UIColor grayColor]
                          :NSTextAlignmentCenter];
    [_moneyTypeLabel setInfo:[UIFont systemFontOfSize:14.0f*SCALING]
                         :[UIColor blackColor]
                         :NSTextAlignmentLeft];
    [self addSubview:_moneyTypeLabel];
    
    tempFrame.origin.y += CGRectGetHeight(tempFrame);
    _buyTimeLabel = [UITitleInfo initTitleInfo:self frame:tempFrame title:@"购买时长:"];
    [_buyTimeLabel setTitle:[UIFont systemFontOfSize:14.0f*SCALING]
                         :[UIColor grayColor]
                         :NSTextAlignmentCenter];
    [_buyTimeLabel setInfo:[UIFont systemFontOfSize:14.0f*SCALING]
                        :[UIColor blackColor]
                        :NSTextAlignmentLeft];
    [self addSubview:_buyTimeLabel];
    
    tempFrame.origin.y += CGRectGetHeight(tempFrame);
    _buyNumberLabel = [UITitleInfo initTitleInfo:self frame:tempFrame title:@"购买次数:"];
    [_buyNumberLabel setTitle:[UIFont systemFontOfSize:14.0f*SCALING]
                       :[UIColor grayColor]
                       :NSTextAlignmentCenter];
    [_buyNumberLabel setInfo:[UIFont systemFontOfSize:14.0f*SCALING]
                      :[UIColor blackColor]
                      :NSTextAlignmentLeft];
    [self addSubview:_buyNumberLabel];
    
    tempFrame.origin.y += CGRectGetHeight(tempFrame);
    _moneyLabel = [UITitleInfo initTitleInfo:self frame:tempFrame title:@"应付金额:"];
    [_moneyLabel setTitle:[UIFont systemFontOfSize:14.0f*SCALING]
                             :[UIColor grayColor]
                             :NSTextAlignmentCenter];
    [_moneyLabel setInfo:[UIFont systemFontOfSize:14.0f*SCALING]
                            :[UIColor blackColor]
                            :NSTextAlignmentLeft];
    [self addSubview:_moneyLabel];
    
    tempFrame.origin.y += CGRectGetHeight(tempFrame);
    _discountLabel = [UITitleInfo initTitleInfo:self frame:tempFrame title:@"优惠金额:"];
    [_discountLabel setTitle:[UIFont systemFontOfSize:14.0f*SCALING]
                         :[UIColor grayColor]
                         :NSTextAlignmentCenter];
    [_discountLabel setInfo:[UIFont systemFontOfSize:14.0f*SCALING]
                        :[UIColor blackColor]
                        :NSTextAlignmentLeft];
    [self addSubview:_discountLabel];
    
    tempFrame.origin.y += CGRectGetHeight(tempFrame);
    _discountReasonLabel = [UITitleInfo initTitleInfo:self frame:tempFrame title:@"优惠原因:"];
    [_discountReasonLabel setTitle:[UIFont systemFontOfSize:14.0f*SCALING]
                       :[UIColor grayColor]
                       :NSTextAlignmentCenter];
    [_discountReasonLabel setInfo:[UIFont systemFontOfSize:14.0f*SCALING]
                      :[UIColor blackColor]
                      :NSTextAlignmentLeft];
    [self addSubview:_discountReasonLabel];
    
    tempFrame.origin.y += CGRectGetHeight(tempFrame);
    _payLabel = [UITitleInfo initTitleInfo:self frame:tempFrame title:@"实付金额:"];
    [_payLabel setTitle:[UIFont systemFontOfSize:14.0f*SCALING]
                             :[UIColor grayColor]
                             :NSTextAlignmentCenter];
    [_payLabel setInfo:[UIFont systemFontOfSize:14.0f*SCALING]
                            :[UIColor blackColor]
                            :NSTextAlignmentLeft];
    [self addSubview:_payLabel];
}

#pragma mark -
-(void)layoutSubviews
{
    [super layoutSubviews];
    
    [self.orderNumberLabel setInfo:self.detail.billNo];
    [self.orderTimeLabel setInfo:self.detail.createDate];
    [self.subjectLabel setInfo:[self.detail getSubject]];
    [self.serviceLabel setInfo:self.detail.schoolName];
    [self.fieldLabel setInfo:self.detail.mockexamAreaName];
    [self.carLabel setInfo:self.detail.vehicleTypeName];
     NSString *serviceType = @"";
     if (self.detail.serviceType == 1) {//服务收费类型，1：按时长分钟  2：按次数
         serviceType = @"按时长";
     }
     else if (self.detail.serviceType == 2) {
         serviceType = @"按次数";
     }
    [self.moneyTypeLabel setInfo:serviceType];
    [self.buyTimeLabel setInfo:[NSString stringWithFormat:@"%@分钟", @(self.detail.pricePerMin)]];
    [self.buyNumberLabel setInfo:[NSString stringWithFormat:@"%@次", @(self.detail.purchaseTrainCount)]];
    [self.moneyLabel setInfo:[NSString stringWithFormat:@"%.02f元", self.detail.shouldPayPrice]];
    [self.discountLabel setInfo:[NSString stringWithFormat:@"%.02f元", self.detail.discountMoney]];
    [self.discountReasonLabel setInfo:self.detail.discountReason];
    [self.payLabel setInfo:[NSString stringWithFormat:@"%.02f元", self.detail.infactPayPrice]];
    
    [self.stateLabel setText:@"交易完成"];
}

@end

